extends Spatial

var StarScene = preload("res://Star.tscn")
onready var MAIN = find_parent("MAIN")

var radius = 3000
var n =10000
var star_scale = 0.1

var norm = Vector3(0,0,1)

# Called when the node enters the scene tree for the first time.
func _ready():
	randomize()
	generate_stars()
	pass # Replace with function body.

func _process(_delta):
	var gamma = sqrt(1/(1-(MAIN.beta.length_squared())))
	print(gamma)
	transform.basis = make_basis(gamma, norm).inverse()
	pass

func make_basis(gamma,norm):
	var gmo = gamma - 1
	var unit_bas = Basis(Vector3(0,0,0))
	var n = norm*sqrt(gmo)
	var bas = n.outer(n)
	bas=basis_add(bas, unit_bas)
	return bas

func basis_add(b1,b2):
	var ret = Basis()
	ret.x = b1.x+b2.x
	ret.y = b1.y+b2.y
	ret.z = b1.z+b2.z
	return ret

func generate_stars():
	for _i in range(n):
#		var r = rand_range(0,radius)
#		var theta = rand_range(-PI/2.0,PI/2.0)
#		var phi = rand_range(0,2*PI)
		var star = StarScene.instance()
#		star.translation.x = r*cos(theta)*sin(phi)
#		star.translation.z = r*cos(theta)*cos(phi)
#		star.translation.y = r*sin(theta)
		star.translation.x = rand_range(0,500) - 500/2
		star.translation.y = rand_range(0,500) - 500/2
		star.translation.z = rand_range(0,radius) - radius/2
		star.scale = Vector3(1,1,1)*star_scale

		add_child(star)
